package com.human.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.human.entity.Appraise;
import com.human.dao.AppraiseMapper;
import com.human.entity.ResultVo;
import com.human.service.IAppraiseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评估 服务实现类
 * </p>
 *
 * @author jzq
 * @since 2023-03-09
 */
@Service
public class AppraiseServiceImpl extends ServiceImpl<AppraiseMapper, Appraise> implements IAppraiseService {

    @Resource
    AppraiseMapper appraiseMapper;

    @Override
    public ResultVo page(int current, int pageSize, String name) {
        Page pageInfo = new Page(current, pageSize);
        IPage page = appraiseMapper.getAll(pageInfo, name);
        return new ResultVo<Page>(true, "查询成功", page);
    }

    @Override
    public ResultVo getAllAppraises() {
        List<Appraise> appraiseList = appraiseMapper.selectList(null);
        return new ResultVo(true, "查询成功", appraiseList);
    }

    @Override
    public ResultVo getAppraiseById(Integer id) {
        Appraise appraise = appraiseMapper.selectById(id);
        return new ResultVo(true, "查询成功", appraise);
    }

    @Override
    public ResultVo updateAppraise(Appraise appraise) {
        int i = appraiseMapper.updateById(appraise);
        if (i > 0) {
            return new ResultVo(true, "修改成功");
        }
        return new ResultVo(true, "修改失败");
    }

    @Override
    public ResultVo addAppraise(Appraise appraise) {
        int i = appraiseMapper.insert(appraise);
        if (i > 0) {
            return new ResultVo(true, "添加成功");
        }
        return new ResultVo(true, "添加失败");
    }

    @Override
    public ResultVo deleteAppraiseById(Integer id) {
        int i = appraiseMapper.deleteById(id);
        if (i > 0) {
            return new ResultVo(true, "删除成功");
        }
        return new ResultVo(true, "删除失败");
    }


}
